#include "stdio.h"
#include "stdlib.h"

#define MAXSIZE 100
typedef int DataType;
typedef struct {
    DataType *base;
    int front[2];
    int rear[2];
}DQueue;

int InitQueue(DQueue *Q) {
    Q->base = (DataType *)malloc(sizeof(DataType) * MAXSIZE);
    if (Q->base == NULL) {
        return 0;
    }
    Q->front[0] = 0;
    Q->rear[0] = 0;
    Q->front[1] = 0;
    Q->rear[1] = 0;
    return 1;
}
//判断i队列是否为空
int QueueEmpty(DQueue Q,int i) {
    if (Q.front[i] == Q.rear[i]) {
        return 1;
    }
    return 0;
}

//获取i队列的长度
int QueueLength(DQueue Q,int i) {
    if (Q.front[i] == Q.rear[i]) {
        return 0;
    }
    return Q.rear[i] - Q.front[i] + 1;
}

//获取i队列的队头元素
int QueueHead(DQueue Q,int i) {
    if (Q.front[i] == Q.rear[i]) {
        return 0;
    }
    return Q.base[Q.front[i]];
}

//对i队列进行添加
int Enqueue(DQueue *Q,int i,DataType x) {
    if (QueueLength(*Q,i) == MAXSIZE) {
        return 1;
    }
    Q->base[Q->rear[i]] = x;
    Q->rear[i] = (Q->rear[i] + 1) % MAXSIZE;
    return 0;
}

//对i队列进行取出
int Dequeue(DQueue *Q,int i,DataType *x) {
    if (QueueLength(*Q,i) == 0) {
        return 1;
    }
    *x = Q->base[Q->front[i]];
    Q->front[i] = (Q->front[i] + 1) % MAXSIZE;
    return 0;
}

//判断队列满了
int QueueFull(DQueue Q) {
    if (Q.rear[0] == Q.rear[1]) {
        return 0;
    }
    return 1;
}